<template>
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="practice.p_id" label="实践序号" width="170">
    </el-table-column>
    <el-table-column prop="practice.p_name" label="实践名称" width="170">
    </el-table-column>
    <el-table-column prop="practice.address" label="实践地址" width="170">
    </el-table-column>
    <el-table-column prop="practice.start_time" label="起始时间" width="170">
    </el-table-column>
    <el-table-column prop="practice.end_time" label="结束时间" width="170">
    </el-table-column>
    <el-table-column prop="score" label="获得分数" width="170">
    </el-table-column>
    <el-table-column label="我的感想" width="170">
      <template slot-scope="scope">
        <el-button
          icon="el-icon-search"
          circle
          @click="searchthink(scope.$index, tableData)"
        ></el-button>
        <el-button
          type="primary"
          icon="el-icon-edit"
          circle
          @click="fillthink(scope.$index)"
        ></el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      s_id: JSON.parse(sessionStorage.getItem("student")).s_id
    };
  },
  created() {
    this.$axios
      .post(
        "/api/student/findmypractice",
        this.$qs.stringify({ s_id: this.s_id })
      )
      .then(res => {
        this.tableData = res.data;
      });
  },
  methods: {
    searchthink(index,rows) {
        if(rows[index].think=='' ||rows[index].think==null)
        {alert('你还未填写感想')}
        else alert(rows[index].think);
    },
    fillthink(index) {
      this.$prompt("请填写你的感想", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(value => {
          this.$axios.post(
            "/api/student/insertthink",
            this.$qs.stringify({
              s_id: this.s_id,
              p_id: this.tableData[index].practice.p_id,
              think: value
            })
          );
          this.$message({
            type: "success",
            message: "填写成功"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消填写"
          });
        });
    }
  }
};
</script>

<style></style>
